<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$user_id = get_loggedin_userid();
$noun_id = $user_id;

$adjective_id = get_input('adjective_id');
$noun = get_input('noun');
$noun_url = get_input('noun_url');
$noun_thumbnail_url = get_input('noun_thumbnail_url');
$prev_game_id = get_input('prev_game_id');
$turn = get_input('turn');

$noun_coin = 5;//get_input('noun_coin');

$s = FALSE;

if ($prev_game_id) {
    $s = dt_update_game_holder($noun_id, $adjective_id, $prev_game_id, $noun, $noun_url, $noun_thumbnail_url, $noun_coin);
}

if (!$s) {
    $s = dt_create_game($noun_id, $adjective_id, $noun, $noun_url, $noun_thumbnail_url, $prev_game_id, $turn, $noun_coin);
}

if($s) {
    $noun_user = dt_get_user_by_user_id($noun_id);
    $adjective_user = dt_get_user_by_user_id($adjective_id);
    $noun_name = $noun_user->fullname;
    $adjective_name = $adjective_user->fullname;
    $message = "Hey $adjective_name, $noun_name has started a drawing game with you, complete the drawing now.";
    dt_send_push_notification($adjective_id, $message, FALSE);
    //dt_send_push_notification($adjective_id, $message, FALSE);
    dt_update_coins($user_id, $noun_coin);
    echo json_encode(export_result(200, "1"));
} else {
    echo json_encode(export_result(400, "0"));
}

?>
